package com.kyle.redpacket.dto.result;

import java.sql.Timestamp;

public class Result<T> {

    private ResultEnum resultEnum;

    private T data;//数据

    //------------APIS---------------------------
    public static <S> Result<S> isOk() {
        Result<S> Result = new Result<>();
        Result.setResultEnum(ResultEnum.SUCCESS);
        Result.setData(null);
        return Result;
    }

    public static <S> Result<S> isOk(S data) {
        Result<S> Result = new Result<>();
        Result.setResultEnum(ResultEnum.SUCCESS);
        Result.setData(data);
        return Result;
    }

    public static <S> Result<S> isFail() {
        Result<S> Result = new Result<>();
        Result.setResultEnum(ResultEnum.UNKONW_ERROR);
        Result.setData(null);
        return Result;
    }

    public static <S> Result<S> isFail(S data) {
        Result<S> Result = new Result<>();
        Result.setResultEnum(ResultEnum.UNKONW_ERROR);
        Result.setData(data);
        return Result;
    }

    public static <S> Result<S> isFail(ResultEnum resultEnum) {
        Result<S> Result = new Result<>();
        Result.setResultEnum(resultEnum);
        return Result;
    }

    public static <S> Result<S> isFail(ResultEnum resultEnum, S data) {
        Result<S> Result = new Result<>();
        Result.setResultEnum(resultEnum);
        Result.setData(data);
        return Result;
    }
    //-------------------------------------------------------------------


    public int getCode() {
        return resultEnum.getCode();
    }

    public String getMsg() {
        return resultEnum.getMsg();
    }

    public void setResultEnum(ResultEnum resultEnum) {
        this.resultEnum = resultEnum;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Timestamp getTimestamp() {
        return new Timestamp(System.currentTimeMillis());
    }

    @Override
    public String toString() {
        return "Result{" +
                "resultEnum=" + resultEnum +
                ", data=" + data +
                '}';
    }
}